#include "Driver_24BYJ48\Driver_24BYJ48.h"

/* 电机D1各引脚的电平改变函数 */
void D1_1_Write(uint8_t x){
    HAL_GPIO_WritePin(D1_1_GPIO_Port, D1_1_Pin, (GPIO_PinState)x);
}

void D1_2_Write(uint8_t x){
    HAL_GPIO_WritePin(D1_2_GPIO_Port, D1_2_Pin, (GPIO_PinState)x);
}

void D1_3_Write(uint8_t x){
    HAL_GPIO_WritePin(D1_3_GPIO_Port, D1_3_Pin, (GPIO_PinState)x);
}

void D1_4_Write(uint8_t x){
    HAL_GPIO_WritePin(D1_4_GPIO_Port, D1_4_Pin, (GPIO_PinState)x);
}

/* 电机D2各引脚的电平改变函数 */
void D2_1_Write(uint8_t x){
    HAL_GPIO_WritePin(D2_1_GPIO_Port, D2_1_Pin, (GPIO_PinState)x);
}

void D2_2_Write(uint8_t x){
    HAL_GPIO_WritePin(D2_2_GPIO_Port, D2_2_Pin, (GPIO_PinState)x);
}

void D2_3_Write(uint8_t x){
    HAL_GPIO_WritePin(D2_3_GPIO_Port, D2_3_Pin, (GPIO_PinState)x);
}
void D2_4_Write(uint8_t x){
    HAL_GPIO_WritePin(D2_4_GPIO_Port, D2_4_Pin, (GPIO_PinState)x);
}

/* 电机D3各引脚的电平改变函数 */
void D3_1_Write(uint8_t x){
    HAL_GPIO_WritePin(D3_1_GPIO_Port, D3_1_Pin, (GPIO_PinState)x);
}

void D3_2_Write(uint8_t x){
    HAL_GPIO_WritePin(D3_2_GPIO_Port, D3_2_Pin, (GPIO_PinState)x);
}

void D3_3_Write(uint8_t x){
    HAL_GPIO_WritePin(D3_3_GPIO_Port, D3_3_Pin, (GPIO_PinState)x);
}

void D3_4_Write(uint8_t x){
    HAL_GPIO_WritePin(D3_4_GPIO_Port, D3_4_Pin, (GPIO_PinState)x);
}

/* 电机D4各引脚的电平改变函数 */
void D4_1_Write(uint8_t x){
    HAL_GPIO_WritePin(D4_1_GPIO_Port, D4_1_Pin, (GPIO_PinState)x);
}

void D4_2_Write(uint8_t x){
    HAL_GPIO_WritePin(D4_2_GPIO_Port, D4_2_Pin, (GPIO_PinState)x);
}

void D4_3_Write(uint8_t x){
    HAL_GPIO_WritePin(D4_3_GPIO_Port, D4_3_Pin, (GPIO_PinState)x);
}

void D4_4_Write(uint8_t x){
    HAL_GPIO_WritePin(D4_4_GPIO_Port, D4_4_Pin, (GPIO_PinState)x);
}

/* 电机D5各引脚的电平改变函数 */
void D5_1_Write(uint8_t x){
    HAL_GPIO_WritePin(D5_1_GPIO_Port, D5_1_Pin, (GPIO_PinState)x);
}

void D5_2_Write(uint8_t x){
    HAL_GPIO_WritePin(D5_2_GPIO_Port, D5_2_Pin, (GPIO_PinState)x);
}   

void D5_3_Write(uint8_t x){
    HAL_GPIO_WritePin(D5_3_GPIO_Port, D5_3_Pin, (GPIO_PinState)x);
}

void D5_4_Write(uint8_t x){
    HAL_GPIO_WritePin(D5_4_GPIO_Port, D5_4_Pin, (GPIO_PinState)x);
}

void Motor8_Init(Motor *motor,void (*Dx_1)(uint8_t x),void (*Dx_2)(uint8_t x),void (*Dx_3)(uint8_t x),void (*Dx_4)(uint8_t x))
{
    motor->writeA = Dx_1;
    motor->writeB = Dx_2;
    motor->writeC = Dx_3;
    motor->writeD = Dx_4;
}

void Motor8(Motor *motor,uint8_t i,uint8_t dir)
{
	if(dir == 1)
    {
        switch(i){
            case 1:
                motor->writeA(0);
                motor->writeB(1);
                motor->writeC(1);
                motor->writeD(1);
            break;
            case 2:
                motor->writeA(0);
                motor->writeB(0);
                motor->writeC(1);
                motor->writeD(1);
            break;
            case 3:
                motor->writeA(1);
                motor->writeB(0);
                motor->writeC(1);
                motor->writeD(1);
            break;
            case 4:
                motor->writeA(1);
                motor->writeB(0);
                motor->writeC(0);
                motor->writeD(1);
            break;
            case 5:
                motor->writeA(1);
                motor->writeB(1);
                motor->writeC(0);
                motor->writeD(1);
            break;
            case 6:
                motor->writeA(1);
                motor->writeB(1);
                motor->writeC(0);
                motor->writeD(0);
            break;
            case 7:
                motor->writeA(1);
                motor->writeB(1);
                motor->writeC(1);
                motor->writeD(0);
            break;
            case 8:
                motor->writeA(0);
                motor->writeB(1);
                motor->writeC(1);
                motor->writeD(0);
            break;
            default:
                break;
        }
    }
    else{
        switch(i){
            case 1:
                motor->writeA(0);
                motor->writeB(1);
                motor->writeC(1);
                motor->writeD(0);
            break;
            case 2:
                motor->writeA(1);
                motor->writeB(1);
                motor->writeC(1);
                motor->writeD(0);
            break;
            case 3:
                motor->writeA(1);
                motor->writeB(1);
                motor->writeC(0);
                motor->writeD(0);
            break;
            case 4:
                motor->writeA(1);
                motor->writeB(1);
                motor->writeC(0);
                motor->writeD(1);
            break;
            case 5:
                motor->writeA(1);
                motor->writeB(0);
                motor->writeC(0);
                motor->writeD(1);
            break;
            case 6:
                motor->writeA(1);
                motor->writeB(0);
                motor->writeC(1);
                motor->writeD(1);
            break;
            case 7:
                motor->writeA(0);
                motor->writeB(0);
                motor->writeC(1);
                motor->writeD(1);
            break;
            case 8:
                motor->writeA(0);
                motor->writeB(1);
                motor->writeC(1);
                motor->writeD(1);
            default:
                break;
        }
    }


}

Motor A;
